#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
struct node{
    ll st,en;
}cow[30000];

bool cmp(node a,node b){
    if(a.st==b.st){
        return  a.en>b.en;
    }
    return a.st<b.st;
}

int main()
{
    IOS;
    ll n,t;
    cin>>n>>t;
    for(ll i=1;i<=n;i++){
        cin>>cow[i].st>>cow[i].en;
    }
    sort(cow+1,cow+1+n,cmp);
    ll left=0,ans=0,newleft=0;
    bool flag=true;
    for(ll i=1;i<=n&&flag;){
        while(cow[i].st<=left+1&&i<=n){
            if(newleft<cow[i].en){
                newleft=cow[i].en;
            }
            i++;
        }
        // cout<<"left="<<left<<endl;
        if(newleft>=left+1){
            ans++;
            left=newleft;
            if(left>=t){
                break;
            }
        }
        else flag=false;
    }
    if(flag&&newleft>=t){
        cout<<ans<<endl;
    }
    else cout<<-1<<endl;
    getchar();
    getchar();
    return 0;
}
